const http = require('http')
const url = require('url')
const routes = require('./module/route')
const ejs = require('ejs')

http.createServer(function (req, res) {
  
  // 创建静态web服务
  routes.static(req, res, 'static')
  // 路由
  let pathname = url.parse(req.url).pathname.replace('/', '')
  try {
    routes[pathname](req, res)
  } catch (error) {
    routes['error'](req, res)
  }

}).listen(8081)

console.log('Server running at http://localhost:8081/')